package com.dycong.common.reflect.aop.anno;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class GreetingAspectNew {

    /*定义切入点  */
    @SuppressWarnings("unused")
    @Pointcut("execution(* Spring.aop.anno.GreetingImplNew.*(..))")
    public void pointcut() {
        System.out.println("this is the pointcut");
    }

    @Around("pointcut()")
    public Object around(ProceedingJoinPoint pjp) throws Throwable {
        before();
        Object result = pjp.proceed();
        after();
        return result;
    }

    @Before("execution(* Spring.aop.anno.GreetingImplNew.*(..))")
    public void doSthBefore() {
        System.out.println("this is the before AOP");
    }

    @After("pointcut()")
    public void doSthAfter() {
        System.out.println("this is the doSthAfter AOP");
    }

    @AfterThrowing("pointcut()")
    public void doSthAfterThrowing() {
        System.out.println("this is the doSthAfterThrowing AOP");
    }

    @AfterReturning("pointcut()")
    public void doSthAfterReturn() {
        System.out.println("this is the doSthAfterReturn AOP");
    }

    private void before() {
        System.out.println("Before");
    }


    private void after() {
        System.out.println("After");
    }

}
